package com.example.demo.controller;

import com.example.demo.controller.data.ReturnData;
import com.example.demo.controller.vo.RegisterUser;
import com.example.demo.entity.Admin;
import com.example.demo.entity.Circle;
import com.example.demo.entity.User;
import com.example.demo.service.AdminService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/admin")
public class AdminController {
    @Resource
    AdminService adminService;

    /**
     * 登录接口
     */

    @PostMapping("login")
    public ReturnData login(@RequestBody Admin admin){
        return adminService.login(admin.getUsername(),admin.getPassword());
    }


    /**
     * 分页获取所有的用户
     */

    @GetMapping("/user/list")
    public ReturnData list(@RequestParam(defaultValue = "1") int page,
                           @RequestParam(defaultValue = "20")int limit,
                           @RequestParam(defaultValue = "") String nickname){
        return adminService.getUserList(page,limit,nickname);
    }

    /**
     * 根据ID删除用户
     */
    @PostMapping("/user/delete")
    public ReturnData deleteUser(@RequestBody User user){
        return adminService.deleteUser(user.getId());
    }

    /**
     * 根据用户ID编辑用户信息接口
     * @return
     */

    @PostMapping("updateUserInfo")
    public ReturnData upupdateUserInfo(@RequestBody RegisterUser user){

        return adminService.updateUserInfo(user);
    }



    @GetMapping("/circle/list")
    public ReturnData getCircle(@RequestParam(defaultValue = "1") int page,
                                @RequestParam(defaultValue = "20")int pageSize,
                                @RequestParam(defaultValue = "")String content){
        return adminService.getCircle(page,pageSize,content);
    }

    @PostMapping("/circle/delete")
    public ReturnData deleteCircle(@RequestBody Circle circle){
        return adminService.deleteCircle(circle.getId());
    }

    @GetMapping("/comment/list")
    public ReturnData getComment(@RequestParam(defaultValue = "1") int page,
                                 @RequestParam(defaultValue = "20") int pageSize,
                                 int circleId){
        return adminService.getComment(page,pageSize,circleId);
    }
}
